\doxysection{x\+Semaphore\+Take }
\hypertarget{group__x_semaphore_take}{}\label{group__x_semaphore_take}\index{xSemaphoreTake@{xSemaphoreTake}}
semphr. h 
\begin{DoxyPre}xSemaphoreTake(                     SemaphoreHandle\_t xSemaphore,                     TickType\_t xBlockTime                 )\end{DoxyPre}


{\itshape Macro} to obtain a semaphore. The semaphore must have previously been created with a call to x\+Semaphore\+Create\+Binary(), x\+Semaphore\+Create\+Mutex() or x\+Semaphore\+Create\+Counting().


\begin{DoxyParams}{Parameters}
{\em x\+Semaphore} & A handle to the semaphore being taken -\/ obtained when the semaphore was created.\\
\hline
{\em x\+Block\+Time} & The time in ticks to wait for the semaphore to become available. The macro port\+TICK\+\_\+\+PERIOD\+\_\+\+MS can be used to convert this to a real time. A block time of zero can be used to poll the semaphore. A block time of port\+MAX\+\_\+\+DELAY can be used to block indefinitely (provided INCLUDE\+\_\+v\+Task\+Suspend is set to 1 in \doxylink{_free_r_t_o_s_config_8h_source}{Free\+RTOSConfig.\+h}).\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pd\+TRUE if the semaphore was obtained. pd\+FALSE if x\+Block\+Time expired without the semaphore becoming available.
\end{DoxyReturn}
Example usage\+: 
\begin{DoxyPre}
SemaphoreHandle\_t xSemaphore = NULL;

// A task that creates a semaphore.
void vATask( void * pvParameters )
\{
   // Create the semaphore to guard a shared resource.
   xSemaphore = xSemaphoreCreateBinary();
\}

// A task that uses the semaphore.
void vAnotherTask( void * pvParameters )
\{
   // ... Do other things.

   if( xSemaphore != NULL )
   \{
       // See if we can obtain the semaphore.  If the semaphore is not available
       // wait 10 ticks to see if it becomes free.
       if( xSemaphoreTake( xSemaphore, ( TickType\_t ) 10 ) == pdTRUE )
       \{
           // We were able to obtain the semaphore and can now access the
           // shared resource.

           // ...

           // We have finished accessing the shared resource.  Release the
           // semaphore.
           xSemaphoreGive( xSemaphore );
       \}
       else
       \{
           // We could not obtain the semaphore and can therefore not access
           // the shared resource safely.
       \}
   \}
\}
\end{DoxyPre}
 